<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>12-搜索案例</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="app">
            <input type="text" v-model="str">
            <ul>
                <li v-for="(item,index) in arr2" :key="index">{{item}}</li>
            </ul>
        </div>
    </body>

    <script type="text/javascript">
        new Vue({
            el: "#app",
            data: {
                str: "",
                arr: ["小w","小z","中w","中z","大w","大z"],
                arr2: []
            },
            watch: {
                str:{
                    immediate: true,
                    handler(value){
                        let newArr = this.arr.filter(item=>{
                            return item.indexOf(value) !== -1
                        })
                        this.arr2 = newArr
                    }
                }
            }
        })
        
    </script>
</html>